package com.example.common;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * @Description: 统一返回对象
 * @Author Mr.Tang
 */
@Data
public class Result implements Serializable {

    private int code;       // 状态码
    private String msg;     // 状态码描述信息
    private Object data;    // 返回数据

    /**
     *  成功时返回的统一对象
     */
    public static Result success(String msg, Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    /**
     *  成功时返回的统一对象
     */
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("");
        result.setData(data);
        return result;
    }

    /**
     *  成功时返回的统一对象
     */
    public static Result success() {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(null);
        return result;
    }

    /**
     *  失败时返回的统一对象
     */
    public static Result fail(int code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    /**
     *  失败时返回的统一对象
     */
    public static Result fail(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }


}
